<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE RankNTypes, ScopedTypeVariables, Safe #-}</span><span>
</span><span id="line-2"></span><span class="hs-comment">{- |
Module : Language.Haskell.TH.Quote
Description : Quasi-quoting support for Template Haskell

Template Haskell supports quasiquoting, which permits users to construct
program fragments by directly writing concrete syntax.  A quasiquoter is
essentially a function with takes a string to a Template Haskell AST.
This module defines the 'QuasiQuoter' datatype, which specifies a
quasiquoter @q@ which can be invoked using the syntax
@[q| ... string to parse ... |]@ when the @QuasiQuotes@ language
extension is enabled, and some utility functions for manipulating
quasiquoters.  Nota bene: this package does not define any parsers,
that is up to you.
-}</span><span>
</span><span id="line-16"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">Language.Haskell.TH.Quote</span><span class="hs-special">(</span><span>
</span><span id="line-17"></span><span>        </span><span class="annot"><a href="Language.Haskell.TH.Quote.html#QuasiQuoter"><span class="hs-identifier">QuasiQuoter</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span>
</span><span id="line-18"></span><span>        </span><span class="annot"><a href="Language.Haskell.TH.Quote.html#quoteFile"><span class="hs-identifier">quoteFile</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-19"></span><span>        </span><span class="annot"><span class="hs-comment">-- * For backwards compatibility</span></span><span>
</span><span id="line-20"></span><span>        </span><span class="annot"><a href="Language.Haskell.TH.Syntax.html#dataToQa"><span class="hs-identifier">dataToQa</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Language.Haskell.TH.Syntax.html#dataToExpQ"><span class="hs-identifier">dataToExpQ</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Language.Haskell.TH.Syntax.html#dataToPatQ"><span class="hs-identifier">dataToPatQ</span></a></span><span>
</span><span id="line-21"></span><span>    </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-22"></span><span>
</span><span id="line-23"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Language.Haskell.TH.Syntax.html"><span class="hs-identifier">Language.Haskell.TH.Syntax</span></a></span><span>
</span><span id="line-24"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Prelude.html#"><span class="hs-identifier">Prelude</span></a></span><span>
</span><span id="line-25"></span><span>
</span><span id="line-26"></span><span class="hs-comment">-- | The 'QuasiQuoter' type, a value @q@ of this type can be used</span><span>
</span><span id="line-27"></span><span class="hs-comment">-- in the syntax @[q| ... string to parse ...|]@.  In fact, for</span><span>
</span><span id="line-28"></span><span class="hs-comment">-- convenience, a 'QuasiQuoter' actually defines multiple quasiquoters</span><span>
</span><span id="line-29"></span><span class="hs-comment">-- to be used in different splice contexts; if you are only interested</span><span>
</span><span id="line-30"></span><span class="hs-comment">-- in defining a quasiquoter to be used for expressions, you would</span><span>
</span><span id="line-31"></span><span class="hs-comment">-- define a 'QuasiQuoter' with only 'quoteExp', and leave the other</span><span>
</span><span id="line-32"></span><span class="hs-comment">-- fields stubbed out with errors.</span><span>
</span><span id="line-33"></span><span class="hs-keyword">data</span><span> </span><span id="QuasiQuoter"><span class="annot"><a href="Language.Haskell.TH.Quote.html#QuasiQuoter"><span class="hs-identifier hs-var">QuasiQuoter</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="QuasiQuoter"><span class="annot"><a href="Language.Haskell.TH.Quote.html#QuasiQuoter"><span class="hs-identifier hs-var">QuasiQuoter</span></a></span></span><span> </span><span class="hs-special">{</span><span>
</span><span id="line-34"></span><span>    </span><span class="hs-comment">-- | Quasi-quoter for expressions, invoked by quotes like @lhs = $[q|...]@</span><span>
</span><span id="line-35"></span><span>    </span><span id="quoteExp"><span class="annot"><span class="annottext">QuasiQuoter -&gt; String -&gt; Q Exp
</span><a href="Language.Haskell.TH.Quote.html#quoteExp"><span class="hs-identifier hs-var hs-var">quoteExp</span></a></span></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Language.Haskell.TH.Syntax.html#Q"><span class="hs-identifier hs-type">Q</span></a></span><span> </span><span class="annot"><a href="Language.Haskell.TH.Syntax.html#Exp"><span class="hs-identifier hs-type">Exp</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-36"></span><span>    </span><span class="hs-comment">-- | Quasi-quoter for patterns, invoked by quotes like @f $[q|...] = rhs@</span><span>
</span><span id="line-37"></span><span>    </span><span id="quotePat"><span class="annot"><span class="annottext">QuasiQuoter -&gt; String -&gt; Q Pat
</span><a href="Language.Haskell.TH.Quote.html#quotePat"><span class="hs-identifier hs-var hs-var">quotePat</span></a></span></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Language.Haskell.TH.Syntax.html#Q"><span class="hs-identifier hs-type">Q</span></a></span><span> </span><span class="annot"><a href="Language.Haskell.TH.Syntax.html#Pat"><span class="hs-identifier hs-type">Pat</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-38"></span><span>    </span><span class="hs-comment">-- | Quasi-quoter for types, invoked by quotes like @f :: $[q|...]@</span><span>
</span><span id="line-39"></span><span>    </span><span id="quoteType"><span class="annot"><span class="annottext">QuasiQuoter -&gt; String -&gt; Q Type
</span><a href="Language.Haskell.TH.Quote.html#quoteType"><span class="hs-identifier hs-var hs-var">quoteType</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Language.Haskell.TH.Syntax.html#Q"><span class="hs-identifier hs-type">Q</span></a></span><span> </span><span class="annot"><a href="Language.Haskell.TH.Syntax.html#Type"><span class="hs-identifier hs-type">Type</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-40"></span><span>    </span><span class="hs-comment">-- | Quasi-quoter for declarations, invoked by top-level quotes</span><span>
</span><span id="line-41"></span><span>    </span><span id="quoteDec"><span class="annot"><span class="annottext">QuasiQuoter -&gt; String -&gt; Q [Dec]
</span><a href="Language.Haskell.TH.Quote.html#quoteDec"><span class="hs-identifier hs-var hs-var">quoteDec</span></a></span></span><span>  </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Language.Haskell.TH.Syntax.html#Q"><span class="hs-identifier hs-type">Q</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><a href="Language.Haskell.TH.Syntax.html#Dec"><span class="hs-identifier hs-type">Dec</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-42"></span><span>    </span><span class="hs-special">}</span><span>
</span><span id="line-43"></span><span>
</span><span id="line-44"></span><span class="hs-comment">-- | 'quoteFile' takes a 'QuasiQuoter' and lifts it into one that read</span><span>
</span><span id="line-45"></span><span class="hs-comment">-- the data out of a file.  For example, suppose @asmq@ is an</span><span>
</span><span id="line-46"></span><span class="hs-comment">-- assembly-language quoter, so that you can write [asmq| ld r1, r2 |]</span><span>
</span><span id="line-47"></span><span class="hs-comment">-- as an expression. Then if you define @asmq_f = quoteFile asmq@, then</span><span>
</span><span id="line-48"></span><span class="hs-comment">-- the quote [asmq_f|foo.s|] will take input from file @&quot;foo.s&quot;@ instead</span><span>
</span><span id="line-49"></span><span class="hs-comment">-- of the inline text</span><span>
</span><span id="line-50"></span><span class="annot"><a href="Language.Haskell.TH.Quote.html#quoteFile"><span class="hs-identifier hs-type">quoteFile</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Language.Haskell.TH.Quote.html#QuasiQuoter"><span class="hs-identifier hs-type">QuasiQuoter</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Language.Haskell.TH.Quote.html#QuasiQuoter"><span class="hs-identifier hs-type">QuasiQuoter</span></a></span><span>
</span><span id="line-51"></span><span id="quoteFile"><span class="annot"><span class="annottext">quoteFile :: QuasiQuoter -&gt; QuasiQuoter
</span><a href="Language.Haskell.TH.Quote.html#quoteFile"><span class="hs-identifier hs-var hs-var">quoteFile</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Language.Haskell.TH.Quote.html#QuasiQuoter"><span class="hs-identifier hs-type">QuasiQuoter</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">quoteExp :: QuasiQuoter -&gt; String -&gt; Q Exp
</span><a href="Language.Haskell.TH.Quote.html#quoteExp"><span class="hs-identifier hs-var">quoteExp</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621679163046"><span class="annot"><span class="annottext">String -&gt; Q Exp
</span><a href="#local-6989586621679163046"><span class="hs-identifier hs-var">qe</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">quotePat :: QuasiQuoter -&gt; String -&gt; Q Pat
</span><a href="Language.Haskell.TH.Quote.html#quotePat"><span class="hs-identifier hs-var">quotePat</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621679163045"><span class="annot"><span class="annottext">String -&gt; Q Pat
</span><a href="#local-6989586621679163045"><span class="hs-identifier hs-var">qp</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">quoteType :: QuasiQuoter -&gt; String -&gt; Q Type
</span><a href="Language.Haskell.TH.Quote.html#quoteType"><span class="hs-identifier hs-var">quoteType</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621679163044"><span class="annot"><span class="annottext">String -&gt; Q Type
</span><a href="#local-6989586621679163044"><span class="hs-identifier hs-var">qt</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">quoteDec :: QuasiQuoter -&gt; String -&gt; Q [Dec]
</span><a href="Language.Haskell.TH.Quote.html#quoteDec"><span class="hs-identifier hs-var">quoteDec</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621679163043"><span class="annot"><span class="annottext">String -&gt; Q [Dec]
</span><a href="#local-6989586621679163043"><span class="hs-identifier hs-var">qd</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span>
</span><span id="line-52"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">QuasiQuoter :: (String -&gt; Q Exp)
-&gt; (String -&gt; Q Pat)
-&gt; (String -&gt; Q Type)
-&gt; (String -&gt; Q [Dec])
-&gt; QuasiQuoter
</span><a href="Language.Haskell.TH.Quote.html#QuasiQuoter"><span class="hs-identifier hs-type">QuasiQuoter</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">quoteExp :: String -&gt; Q Exp
</span><a href="Language.Haskell.TH.Quote.html#quoteExp"><span class="hs-identifier hs-var">quoteExp</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(String -&gt; Q Exp) -&gt; String -&gt; Q Exp
forall a. (String -&gt; Q a) -&gt; String -&gt; Q a
</span><a href="#local-6989586621679163042"><span class="hs-identifier hs-var">get</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; Q Exp
</span><a href="#local-6989586621679163046"><span class="hs-identifier hs-var">qe</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">quotePat :: String -&gt; Q Pat
</span><a href="Language.Haskell.TH.Quote.html#quotePat"><span class="hs-identifier hs-var">quotePat</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(String -&gt; Q Pat) -&gt; String -&gt; Q Pat
forall a. (String -&gt; Q a) -&gt; String -&gt; Q a
</span><a href="#local-6989586621679163042"><span class="hs-identifier hs-var">get</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; Q Pat
</span><a href="#local-6989586621679163045"><span class="hs-identifier hs-var">qp</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">quoteType :: String -&gt; Q Type
</span><a href="Language.Haskell.TH.Quote.html#quoteType"><span class="hs-identifier hs-var">quoteType</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(String -&gt; Q Type) -&gt; String -&gt; Q Type
forall a. (String -&gt; Q a) -&gt; String -&gt; Q a
</span><a href="#local-6989586621679163042"><span class="hs-identifier hs-var">get</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; Q Type
</span><a href="#local-6989586621679163044"><span class="hs-identifier hs-var">qt</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">quoteDec :: String -&gt; Q [Dec]
</span><a href="Language.Haskell.TH.Quote.html#quoteDec"><span class="hs-identifier hs-var">quoteDec</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(String -&gt; Q [Dec]) -&gt; String -&gt; Q [Dec]
forall a. (String -&gt; Q a) -&gt; String -&gt; Q a
</span><a href="#local-6989586621679163042"><span class="hs-identifier hs-var">get</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; Q [Dec]
</span><a href="#local-6989586621679163043"><span class="hs-identifier hs-var">qd</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-53"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-54"></span><span>   </span><span id="local-6989586621679163054"><span class="annot"><a href="#local-6989586621679163042"><span class="hs-identifier hs-type">get</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Language.Haskell.TH.Syntax.html#Q"><span class="hs-identifier hs-type">Q</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679163054"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Language.Haskell.TH.Syntax.html#Q"><span class="hs-identifier hs-type">Q</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679163054"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-55"></span><span>   </span><span id="local-6989586621679163042"><span class="annot"><span class="annottext">get :: forall a. (String -&gt; Q a) -&gt; String -&gt; Q a
</span><a href="#local-6989586621679163042"><span class="hs-identifier hs-var hs-var">get</span></a></span></span><span> </span><span id="local-6989586621679163038"><span class="annot"><span class="annottext">String -&gt; Q a
</span><a href="#local-6989586621679163038"><span class="hs-identifier hs-var">old_quoter</span></a></span></span><span> </span><span id="local-6989586621679163037"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679163037"><span class="hs-identifier hs-var">file_name</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621679163036"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679163036"><span class="hs-identifier hs-var">file_cts</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO String -&gt; Q String
forall a. IO a -&gt; Q a
</span><a href="Language.Haskell.TH.Syntax.html#runIO"><span class="hs-identifier hs-var">runIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; IO String
</span><a href="../../base/src/System.IO.html#readFile"><span class="hs-identifier hs-var">readFile</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679163037"><span class="hs-identifier hs-var">file_name</span></a></span><span class="hs-special">)</span><span> </span><span>
</span><span id="line-56"></span><span>                                 </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">String -&gt; Q ()
</span><a href="Language.Haskell.TH.Syntax.html#addDependentFile"><span class="hs-identifier hs-var">addDependentFile</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679163037"><span class="hs-identifier hs-var">file_name</span></a></span><span>
</span><span id="line-57"></span><span>                                 </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">String -&gt; Q a
</span><a href="#local-6989586621679163038"><span class="hs-identifier hs-var">old_quoter</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679163036"><span class="hs-identifier hs-var">file_cts</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-58"></span></pre></body></html>